package com.wangjiyuan.giftshuo.ui.fragment.classify.mainfragment;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.wangjiyuan.giftshuo.R;
import com.wangjiyuan.giftshuo.ui.fragment.classify.shop.ShopFragment;
import com.wangjiyuan.giftshuo.ui.fragment.classify.strategy.StrategyFragment;
import com.wangjiyuan.giftshuo.ui.fragment.other.search.SearchFragment;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by QXL on 2016/11/15.
 */
public class ClassifyFragment extends Fragment {

    private List<Fragment> list;
    private MyFragmentPagerAdapter myFragmentPagerAdapter;

    private TabLayout mTabLayout;
    private TextView mTextView;
    private ViewPager mViewPager;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ShopFragment shopFragment=new ShopFragment();
        StrategyFragment strategyFragment=new StrategyFragment();
        list.add(strategyFragment);
        list.add(shopFragment);
        myFragmentPagerAdapter=new MyFragmentPagerAdapter(getFragmentManager(),list);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_classify, container, false);
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        mTabLayout= (TabLayout) view.findViewById(R.id.tabLayout_fragment);
        mTextView= (TextView) view.findViewById(R.id.textView_fragment_search);
        mViewPager= (ViewPager) view.findViewById(R.id.viewPager_fragment);

    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        mViewPager.setAdapter(myFragmentPagerAdapter);
        mTabLayout.setupWithViewPager(mViewPager);
    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        list=new ArrayList<>();
    }

    @Override
    public void onDetach() {
        super.onDetach();
    }

    public interface OnFragmentInteractionListener {
        // TODO: Update argument type and name
        void onFragmentInteraction(Uri uri);
    }
}
